<template>
	<view>
		<view class="content">
			<view class="item-con items-center justify-between">
				<view class="item-title pad items-center">
					<image class="icon" src="../../static/img/bt.png" mode=""></image>
					<view>设备编号</view>
				</view>
				<view class="item-input pad flex-row items-center justify-between">
					<input class="fill  input" v-model="form.num" type="text" placeholder="请输入设备编号" />
					<u-icon @click="handleCode" name="scan" size="45"></u-icon>
				</view>
			</view>
			<view class="item-con items-center justify-between">
				<view class="item-title pad items-center">
					<image class="icon" src="../../static/img/bt.png" mode=""></image>
					<view>车位号</view>
				</view>
				<view class="item-input pad flex-row items-center justify-between">
					<input class="fill  input" v-model="form.carportNum" type="text" placeholder="请输入车位号" />
				</view>
			</view>
			
			<view class="item-con items-center justify-between">
				<view class="item-title pad items-center">
					<image class="icon" src="../../static/img/bt.png" mode=""></image>
					<view>类型</view>
				</view>
				<view class="item-input pad flex-row items-center justify-between" @click="show = true">
					<input disabled class="fill  input" v-model="typeNmae" type="text" placeholder="请选择" />
				</view>
			</view>
			<view class="item-con items-center justify-between">
				<view class="item-title pad items-center">
					<view>充电描述</view>
				</view>
				<view class="item-input pad flex-row items-center justify-between">
					<input class="fill  input" v-model="form.chargingSpeed" type="text" placeholder="请输入" />
				</view>
			</view>
			<view class="item-con items-center justify-between">
				<view class="item-title pad items-center">
					<view>地锁编号</view>
				</view>
				<view class="item-input pad flex-row items-center justify-between">
					<input class="fill  input" v-model="form.dn" type="text" placeholder="请输入" />
				</view>
			</view>
		</view>
		<view class="foot">
			<view v-if="type == '1'" class="btn" hover-class="hover-opacity" @click="submit">添加</view>
			<template v-else>
				<view class="btn" hover-class="hover-opacity" @click="submit">保存</view>
				<view class="btn btn-1" hover-class="hover-opacity" @click="handleDel">删除充电桩</view>
			</template>
			
		</view>
		<u-select v-model="show" @confirm="typeConfirm" :list="typeList"></u-select>
		<mix-loading v-if="isLoading"></mix-loading>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form:{},
				type:'',
				show:false,
				typeList:[{
					label:'快充',
					value:'0'
				},{
					label:'慢充',
					value:'1'
				}],
				typeNmae:'',
				id:''
			};
		},
		onLoad(e) {
			if(e.type) this.type = e.type
			if(e.type == '2') {
				this.form = getApp().globalData.pileEditInfo
				this.typeNmae = this.form.type == '0' ? '快充' : '慢充'
			}
			if(e.id) this.id = e.id
		},
		methods:{
			typeConfirm(e){
				this.typeNmae = e[0].label
				this.form.type = e[0].value
			},
			handleCode(){
				uni.scanCode({
					success:(e)=>{
						let text = e.result.split('num=')[1]
						this.form.num = text
						this.$forceUpdate()
					}
				})
			},
			handleDel(){
				uni.showModal({
					content:'是否继续删除?',
					success:(e)=>{
						if(e.confirm){
							this.delFn()
						}
					}
				})
			},
			async delFn(){
				let res = await this.$request('user/zz-del-station-detail',{
					uid:uni.getStorageSync('uid'),
					id:this.form.id
				})
				if(res.result == '0'){
					this.prePage().refresh()
					this.$util.msg('删除成功')
					this.back()
				}else{
					this.$util.msg(res.resultNote)
				}
			},
			async submit(){
				const { num, carportNum, type } = this.form;
				if (!num) return this.$util.msg('请输入设备编号!')
				if (!carportNum) return this.$util.msg('请输入车位号!')
				if (!type) return this.$util.msg('请选择类型!')
				let res = await this.$request('user/zz-edit-station-detail',{
					...this.form,
					stationId:this.id
				},{showLoading: true})
				if(res.result == '0'){
					this.prePage().refresh()
					this.type == '1' ? this.$util.msg('添加成功') : this.$util.msg('保存成功')
					this.back()
				}else{
					this.$util.msg(res.resultNote)
				}
			}
		},
	}
</script>
<style>
	page{
		background-color: #fff;
	}
</style>
<style lang="scss" scoped> 
	.content{
		padding: 20rpx;
	}
	.pad {
		padding: 0 20rpx;
	}
	
	.item-con {
		padding: 20rpx 0;
		.right-text{
			font-size: 26rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #0091FE;
		}
	}
	
	.item-title {
		font-weight: 500;
		color: #666666;
		font-size: 28rpx;
		.icon{
			width: 14rpx;
			height: 14rpx;
			margin-right: 10rpx;
		}
	}
	
	.item-input {
		width: 70%;
		height: 77rpx;
		background: #F3F3F3;
		border-radius: 20rpx;
	}
	
	.item-textarea {
		background: #F3F3F3;
		padding: 20rpx;
		border-radius: 20rpx;
	}
	
	.textarea {
		height: 246rpx;
		width: 100%;
		font-size: 26rpx;
		font-weight: 500;
		color: #999999;
	}
	
	.foot{
		padding-bottom: 30rpx;
		.btn {
			width: 649rpx;
			height: 110rpx;
			line-height: 110rpx;
			text-align: center;
			background: $uni-color-bg;
			border-radius: 44rpx;
			font-size: 30rpx;
			font-weight: 500;
			color: #ffffff;
			margin: 30rpx auto;
		}
		.btn-1{
			border: 1rpx solid $uni-color-bg;
			background: #fff;
			color: $uni-color-bg;
			margin-top: 20rpx;
		}
	}
	
</style>
